<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>基于知识图谱的杂豆病虫害问答系统</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

  <!-- plugins:css -->
  <link rel="stylesheet" href="../static/vendors/mdi/css/materialdesignicons.min.css">
  <link rel="stylesheet" href="../static/vendors/base/vendor.bundle.base.css">
  <!-- endinject -->
  <!-- plugin css for this page -->
  <link rel="stylesheet" href="../static/vendors/datatables.net-bs4/dataTables.bootstrap4.css">
  <!-- End plugin css for this page -->
  <!-- inject:css -->
  <link rel="stylesheet" href="../static/css/style.css">
  <!-- endinject -->
  <link rel="shortcut icon" href="../static/images/豆荚.png" />
  <style>
    #home:hover,#QA_Module:hover,#Recommend_Module:hover,#login:hover{
      color:#71c016
    }
    .form-control:focus{
      border-color:#71c016
    }
    .quesiton-card{
    margin-bottom:15px;
    }
    .card-header{
      background-color:rgb(113, 192, 22,0.25);
      color:#71c016;
      font-weight:600;
    }
    .card-header img{
      width:26px;
    }
    .card-header img:hover{
      cursor:pointer;
    }
    .time{
      font-size:14px;
      color:grey;
      float:right;
    }
    .showAll{
      font-size:14px;
      color:#579711;
      text-decoration:underline;
      float:left;
    }
    .showAll:hover{
      color:#71c016;
      cursor:pointer;
    }
    .line__2 {
      display: -webkit-box;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .ask{
      margin-bottom:10px;
      font-weight:600;
    }
    .answer{
      margin-bottom:10px;
      line-height:24px;
    }
    #sort button,#deleteAll button{
      margin:10px 10px 0 0;
    }
    {% block css %} {% endblock %}
  </style>
</head>
<body>
    <!-- partial:partials/_navbar.html -->
    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
      <div class="navbar-brand-wrapper d-flex justify-content-center">
        <div class="navbar-brand-inner-wrapper d-flex justify-content-between align-items-center w-100">
          <a class="navbar-brand brand-logo" href="/"><img src="../static/images/豆荚.png"  style="width:32px;height:32px"/></a>
          <a class="navbar-brand brand-logo-mini" href="/"><img src="../static/images/豆荚.png" alt="logo"/></a>
          <h4 id="title">用户端</h4>
          <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize" id="minimize">
            <span class="mdi mdi-sort-variant"></span>
          </button>
        </div>
      </div>
      <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
        <ul class="navbar-nav navbar-nav-right">
          <li class="nav-item"><a class="nav-link" href="/lg" id="login">登录</a><li>
          <li class="nav-item nav-profile dropdown" id="LoginReady">
            <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" id="profileDropdown" style="display:none">
              <i class="mdi mdi-account-circle" style="color:#71c016"></i>
              <span class="nav-profile-name" id="user">用户</span>
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
              <a class="dropdown-item" data-toggle="modal" data-target="#pwdModal" id="changePWD">
                <i class="mdi mdi-settings" style="color:#71c016"></i>
                更改密码
              </a>
              <a class="dropdown-item" data-toggle="modal" data-target="#listModal" id="myQuestion">
                <i class="mdi mdi-library-books" style="color:#71c016"></i>
                我的提问
              </a>
              <a class="dropdown-item" data-toggle="modal" data-target="#listModal" id="myLike">
                <i class="mdi mdi-star" style="color:#71c016"></i>
                我的收藏
              </a>
              <a class="dropdown-item" id="logout" data-toggle="modal" data-target="#tipModal">
                <i class="mdi mdi-logout" style="color:#71c016"></i>
                退出登录
              </a>
            </div>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="mdi mdi-menu"></span>
        </button>
      </div>
    </nav>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper" >
      <!-- partial:partials/_sidebar.html -->
      <nav class="sidebar sidebar-offcanvas" id="sidebar" style="position:fixed;">
        <ul class="nav">
          <li class="nav-item">
            <a class="nav-link" href="/" id="home" >
              <i class="mdi mdi-home menu-icon" ></i>
              <span class="menu-title" >主页</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/qa" id="QA_Module">
              <i class="mdi mdi-comment-question-outline menu-icon"></i>
              <span class="menu-title">自动问答</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/search" id="Search_Module">
              <i class="mdi mdi-magnify menu-icon"></i>
              <span class="menu-title">图谱检索</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" id="Recommend_Module">
              <i class="mdi mdi-heart-box-outline menu-icon"></i>
              <span class="menu-title">猜你想问</span>
            </a>
          </li>
        </ul>
      </nav>
      <!-- partial -->
      <div class="position-fixed bottom-0 right-0 p-3" style="z-index: 1200; right: 0; bottom: 0;">
        <div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
          <div class="toast-header">
            <strong class="mr-auto">提示</strong>
          </div>
          <div class="toast-body" id="toastText">
            Hello, world! This is a toast message.
          </div>
        </div>
      </div>
      <!-- 退出登录弹框-->
      <div class="modal fade" id="tipModal" tabindex="-1" aria-labelledby="tipModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="tipModalLabel">提示</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              是否退出登录？
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-success" id="logoutBtn">确定</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 跳转登录弹框-->
      <div class="modal fade" id="tipModal2" tabindex="-1" aria-labelledby="tipModalLabel2" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="tipModalLabel2">提示</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              您尚未登录，是否前往登录页面？
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary cancel" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-success" id="confirmLogin">确定</button>
            </div>
          </div>
        </div>
      </div>
      <!--  更改密码弹框-->
      <div class="modal fade" id="pwdModal" tabindex="-1" aria-labelledby="tipModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="pwdModalLabel">更改密码</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <form>
                <div class="form-group">
                  <label for="old_pwd" class="col-form-label">原密码:</label>
                  <input type="password" class="form-control" id="old_pwd">
                </div>
                <div class="form-group">
                  <label for="new_pwd1" class="col-form-label">新密码:</label>
                  <input type="password" class="form-control" id="new_pwd1">
                </div>
                <div class="form-group">
                  <label for="new_pwd2" class="col-form-label">再次确认密码:</label>
                  <input type="password" class="form-control" id="new_pwd2">
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-success" id="pwdBtn">确定</button>
            </div>
          </div>
        </div>
      </div>
      <!--  我的收藏&我的提问弹框-->
      <div class="modal fade" id="listModal" tabindex="-1" aria-labelledby="listModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-xl modal-dialog-scrollable">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="listModalLabel"></h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <div id="sort" style="display:inline-block;vertical-align:middle;"><button type="button" class="btn btn-sm btn-outline-success" id="descendBtn">按时间↓</button><button type="button" class="btn btn-sm btn-outline-secondary disabled" id="ascendBtn">按时间↑</button></div>
              <div id="deleteAll" style="display:inline-block;vertical-align:middle;position:absolute;right:10px"><button type="button" class="btn btn-sm btn-outline-danger" id="deleteAllBtn">删除全部</button></div>
              <div style="height:15px"></div>
              <div id="List"></div>
            </div>
          </div>
        </div>
      </div>
      <!-- 删除提问记录弹框-->
      <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="tipModalLabel2" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="deleteModalLabel">提示</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              是否确认删除所有提问记录？
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary cancel" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-success" id="confirmDelete">确定</button>
            </div>
          </div>
        </div>
      </div>
      <div class="main-panel" style="margin-left:257px">
        <div class="content-wrapper" >
          {% block content %}{% endblock %}
        </div>
        <!-- content-wrapper ends -->
        <!-- partial:partials/_footer.html -->
        <footer class="footer">
        <div class="d-sm-flex justify-content-center justify-content-sm-between">
          <span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © 北京林业大学 191001229 张雯瑷</span>
        </div>
        </footer>
        <!-- partial -->
      </div>
      <!-- main-panel ends -->
    </div>
    <!-- page-body-wrapper ends -->
  </div>
  <!-- container-scroller -->

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
  <!-- plugins:js -->
  <script src="../static/vendors/base/vendor.bundle.base.js"></script>
  <!-- endinject -->
  <!-- Plugin js for this page-->
  <script src="../static/vendors/chart.js/Chart.min.js"></script>
  <script src="../static/vendors/datatables.net/jquery.dataTables.js"></script>
  <script src="../static/vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script>
  <!-- End plugin js for this page-->
  <!-- inject:js -->
  <script src="../static/js/off-canvas.js"></script>
  <script src="../static/js/hoverable-collapse.js"></script>
  <script src="../static/js/template.js"></script>
  <!-- endinject -->
  <!-- Custom js for this page-->
  <script src="../static/js/dashboard.js"></script>
<!--  <script src="../staticjs/data-table.js"></script>-->
  <script src="../static/js/jquery.dataTables.js"></script>
  <script src="../static/js/dataTables.bootstrap4.js"></script>
  <!-- End custom js for this page-->
  <script src="../static/js/jquery.cookie.js" type="text/javascript"></script>
  <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
  <script>
    $(window).resize(function(){
      if($('.main-panel').css('margin-left')=='257px'){
        $('.main-panel').css('margin-left','0px');
        $('#title').css('display','none');
      }
      else if($('.main-panel').css('margin-left')=='0px'){
        $('.main-panel').css('margin-left','257px');
        $('#title').css('display','inline-block');
      }
    });
    $(function(){
        minimize=0; //默认放大
        likeList=[];
        if(localStorage.getItem('login')==null){
          login=0; //默认未登录
          localStorage.setItem('login',login);
        }
        else
          login=localStorage.getItem('login');
        if(login==0){
          $('#login').css('display','inline-block');
          $('#profileDropdown').css('display','none');
        }
        else{
          $('#login').css('display','none');
          $('#profileDropdown').css('display','inline-block');
          username=localStorage.getItem('username');
          $('#username').text(username);
        }
        localStorage.setItem('minimize',minimize);
        username=localStorage.getItem('username');
        $('#user').text(username);
    });
<!--    $('#minimize').click(function(){-->
<!--      var minimize=localStorage.getItem('minimize');-->
<!--      if(minimize==0){-->
<!--        minimize=1; //缩小化-->
<!--        localStorage.setItem('minimize',minimize);-->
<!--        $('#title').css('display','none');-->
<!--      }else{-->
<!--        minimize=0; //放大化-->
<!--        localStorage.setItem('minimize',minimize);-->
<!--        $('#title').css('display','inline-block');-->
<!--      }-->
<!--    })-->
    $('#changePWD').click(function(){
      $('#old_pwd').val('');
      $('#new_pwd1').val('');
      $('#new_pwd2').val('');
    })
    $('#pwdBtn').click(function(){
      username=localStorage.getItem('username');
      old_pwd=$('#old_pwd').val();
      new_pwd1=$('#new_pwd1').val();
      new_pwd2=$('#new_pwd2').val();
      text="";
      if(old_pwd=='')
        text="请输入原密码！";
      else if(new_pwd1=='')
        text="请输入新密码！";
      else if(new_pwd2=='')
        text="请再次输入新密码！";
      else if(new_pwd1.length>8)
        text="请输入8位以内的新密码！";
      else if(new_pwd1!=new_pwd2)
        text="新密码两次输入不一致！";
      else{
        $.ajax({
          type:"POST",
          url:"/pwd",
          data:{'username':username,'old_pwd':old_pwd,'new_pwd':new_pwd1},
          success:function(re){
            re=JSON.parse(re);
            if(re.msg==1){
              text="修改密码成功！";
              setTimeout(function (){
                $('#pwdModal').css('display','none');
                $(".modal-backdrop").remove();
              }, 3500);
            }
            else if(re.msg==0){
              text='原密码输入错误！';
            }
            $('#liveToast').removeClass('hide');
            $('#liveToast').addClass('show');
            $('#toastText').html(text);
            setTimeout(function (){
              $('#liveToast').addClass('hide');
              $('#liveToast').removeClass('show');
            }, 3000);
          }
        })
      }
      $('#liveToast').removeClass('hide');
      $('#liveToast').addClass('show');
      $('#toastText').html(text);
      setTimeout(function (){
        $('#liveToast').addClass('hide');
        $('#liveToast').removeClass('show');
      }, 3000);
    })
    $('#logoutBtn').click(function(){
      login=0; //更改为未登录状态
      localStorage.setItem('login',login);
      localStorage.removeItem('username');
      localStorage.removeItem('password');
      $('#tipModal').css('display','none');
      $(".modal-backdrop").remove();
      $('#login').css('display','inline-block');
      $('#profileDropdown').css('display','none');
      window.location.href="/";
    })
    $('#Recommend_Module').click(function(){
      login=localStorage.getItem('login');
      if(login==0){
        $('#tipModal2').modal('show');
      }else{
        window.location.href="/recommend";
      }
    })
    $('#Recommend_Module').click(function(){
      login=localStorage.getItem('login');
      if(login==0){
        $('#tipModal2').modal('show');
      }else{
        window.location.href="/recommend";
      }
    })
    $('#confirmLogin').click(function(){
      window.location.href="/lg";
    })
    $('.cancel,.close').click(function(){
        $('#tipModal2').modal('hide');
        $('#deleteModal').modal('hide');
    })
    $('#myLike').click(function(){
      $('#listModalLabel').text('我的收藏');
      $('#deleteAll').css('display','none');
      $('#List').html('');
      $('#List').css('text-align','left');
      $.ajax({
        type:"POST",
        url:"/myLike",
        data:{'username':username,'type':0},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            html='';
            data=re.data;
            likeList=data;
            for (var i = 0; i < data.length; i++){
              html = html +'<div class="card quesiton-card">\
              <div class="card-header">\
                <div style="float:left">'+data[i].type+'</div>\
                <div style="float:right" ><img src="../static/images/未收藏.png" class="dislike" style="display:none"><img src="../static/images/收藏.png" class="like"></div>\
              </div>\
              <div class="card-body">\
                <div class="ask">'+data[i].content+'</div>\
                <div class="answer ">'+data[i].answer+'</div>\
                <div class="time">'+data[i].time+'</div>\
              </div>\
              </div>';
            }
            $('#List').html(html);
          }else if(re.msg==0){
            $('#List').html('<img src="../static/images/暂无收藏.png" style="margin:0 auto;width:450px">');
            $('#List').css('text-align','center');
            $('#sort').css('display','none');
          }
        }
      })
    })
    $(document).on('click','.dislike',function(){
      var username=localStorage.getItem('username');
      var ask=$(this).parents('.card-header').siblings(".card-body").children('.ask').html();
      var obj=$(this);
      $.ajax({
        type:"POST",
        url:"/like",
        data:{'username':username,'ask':ask,'type':'addLike'},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            text='收藏成功！';
            obj.css('display','none');
            obj.siblings('.like').css('display','inline-block');
          }
          else
            text='该问题已被收藏！';
          $('#liveToast').removeClass('hide');
          $('#liveToast').addClass('show');
          $('#toastText').html(text);
          setTimeout(function (){
            $('#liveToast').addClass('hide');
            $('#liveToast').removeClass('show');
          }, 3000);
        }
      })
    })
    $(document).on('click','.like',function(){
      var username=localStorage.getItem('username');
      var ask=$(this).parents('.card-header').siblings(".card-body").children('.ask').html();
      var obj=$(this);
      $.ajax({
        type:"POST",
        url:"/like",
        data:{'username':username,'ask':ask,'type':'removeLike'},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            text='取消收藏成功！';
            obj.css('display','none');
            obj.siblings('.dislike').css('display','inline-block');
          }
          else
            text='该问题未被收藏！';
          $('#liveToast').removeClass('hide');
          $('#liveToast').addClass('show');
          $('#toastText').html(text);
          setTimeout(function (){
            $('#liveToast').addClass('hide');
            $('#liveToast').removeClass('show');
          }, 3000);
        }
      })
    })
    $('#myQuestion').click(function(){
      $('#listModalLabel').text('我的提问');
      $('#deleteAll').css('display','inline-block');
      $('#List').html('');
      $('#List').css('text-align','left');
      $.ajax({
        type:"POST",
        url:"/myQuestion",
        data:{'username':username,'type':0},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            html='';
            data=re.data;
            likeList=data;
            for (var i = 0; i < data.length; i++){
              html = html +'<div class="card quesiton-card">\
              <div class="card-header">\
                <div style="float:left">'+data[i].type+'</div>\
                <div style="float:right" ><img src="../static/images/删除.png" class="delete"></div>\
              </div>\
              <div class="card-body">\
                <div class="ask">'+data[i].content+'</div>\
                <div class="answer ">'+data[i].answer+'</div>\
                <div class="time">'+data[i].time+'</div>\
              </div>\
              </div>';
            }
            $('#List').html(html);
          }
          else if(re.msg==0){
            $('#List').html('<img src="../static/images/查无记录.png" style="margin:0 auto;width:450px">');
            $('#List').css('text-align','center');
            $('#sort').css('display','none');
            $('#deleteAll').css('display','none');
          }
        }
      })
    })
    $('#descendBtn').click(function(){
      var func=$('#listModalLabel').text();
      var url='';
      if(func=='我的收藏')
        url="/myLike";
      else if(func=='我的提问')
        url="/myQuestion";
      $.ajax({
        type:"POST",
        url:url,
        data:{'username':username,'type':1},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            html='';
            data=re.data;
            likeList=data;
            for (var i = 0; i < data.length; i++){
              html = html +'<div class="card quesiton-card">\
              <div class="card-header">\
                <div style="float:left">'+data[i].type+'</div>\
                <div style="float:right" >'
              if(func=='我的收藏')
                html+='<img src="../static/images/未收藏.png" class="dislike" style="display:none"><img src="../static/images/收藏.png" class="like">';
              else if(func=='我的提问')
                html+='<img src="../static/images/删除.png" class="delete">';
              html+='</div>\
              </div>\
              <div class="card-body">\
                <div class="ask">'+data[i].content+'</div>\
                <div class="answer ">'+data[i].answer+'</div>\
                <div class="time">'+data[i].time+'</div>\
              </div>\
              </div>';
            }
            $('#List').html(html);
            $('#descendBtn').removeClass('btn-outline-success');
            $('#descendBtn').addClass('btn-outline-secondary disabled');
            $('#ascendBtn').addClass('btn-outline-success');
            $('#ascendBtn').removeClass('btn-outline-secondary disabled');
          }
        }
      })
    })
    $('#ascendBtn').click(function(){
      var func=$('#listModalLabel').text();
      var url='';
      if(func=='我的收藏')
        url="/myLike";
      else if(func=='我的提问')
        url="/myQuestion";
      $.ajax({
        type:"POST",
        url:url,
        data:{'username':username,'type':0},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            html='';
            data=re.data;
            likeList=data;
            for (var i = 0; i < data.length; i++){
              html = html +'<div class="card quesiton-card">\
              <div class="card-header">\
                <div style="float:left">'+data[i].type+'</div>\
                <div style="float:right" >'
              if(func=='我的收藏')
                html+='<img src="../static/images/未收藏.png" class="dislike" style="display:none"><img src="../static/images/收藏.png" class="like">';
              else if(func=='我的提问')
                html+='<img src="../static/images/删除.png" class="delete">';
              html+='</div>\
              </div>\
              <div class="card-body">\
                <div class="ask">'+data[i].content+'</div>\
                <div class="answer ">'+data[i].answer+'</div>\
                <div class="time">'+data[i].time+'</div>\
              </div>\
              </div>';
            }
            $('#List').html(html);
            $('#ascendBtn').removeClass('btn-outline-success');
            $('#ascendBtn').addClass('btn-outline-secondary disabled');
            $('#descendBtn').addClass('btn-outline-success');
            $('#descendBtn').removeClass('btn-outline-secondary disabled');
          }
        }
      })
    })
    $(document).on('click','.delete',function(){
      var username=localStorage.getItem('username');
      var ask=$(this).parents('.card-header').siblings(".card-body").children('.ask').html();
      var time=$(this).parents('.card-header').siblings(".card-body").children('.time').html();
      var obj=$(this);
      $.ajax({
        type:"POST",
        url:"/delQuestion",
        data:{'username':username,'ask':ask,'time':time,'type':0},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1){
            text='删除成功！';
            obj.parents('.card').css('display','none');
          }
          else
            text='删除失败！';
          $('#liveToast').removeClass('hide');
          $('#liveToast').addClass('show');
          $('#toastText').html(text);
          setTimeout(function (){
            $('#liveToast').addClass('hide');
            $('#liveToast').removeClass('show');
          }, 3000);
        }
      })
    })
    $('#deleteAllBtn').click(function(){
      $('#listModal').css('display','none');
      $(".modal-backdrop").remove();
      $('#deleteModal').modal('show');
    })
    $(document).on('click','#confirmDelete',function(){
      var username=localStorage.getItem('username');
      $.ajax({
        type:"POST",
        url:"/delQuestion",
        data:{'username':username,'type':1},
        success:function(re){
          re=JSON.parse(re);
          if(re.msg==1)
            text='删除成功！';
          else
            text='删除失败！';
          $('#liveToast').removeClass('hide');
          $('#liveToast').addClass('show');
          $('#toastText').html(text);
          setTimeout(function (){
            $('#liveToast').addClass('hide');
            $('#liveToast').removeClass('show');
          }, 3000);
          $('#deleteModal').modal('hide');
        }
      })
    })
    {% block js %} {% endblock %}
  </script>
</body>
</html>

